<?php

/**
 * 原型模式：使用clone copy一个对象。
 * Class Prototype
 * 开销大或者和某个对象类似
 */

class Sheep
{
    protected $name;
    protected $category;

    public function __construct(string $name, string $category = 'Mountain Sheep')
    {
        $this->name = $name;
        $this->category = $category;
    }

    public function setName(string $name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setCategory(string $category)
    {
        $this->category = $category;
    }

    public function getCategory()
    {
        return $this->category;
    }
}

//usage
$original = new Sheep('Jolly');
echo $original->getName();
echo $original->getCategory();

echo "\n克隆一个\n";

// 克隆
$cloned = clone $original;
echo $cloned->setName('Dolly');
echo $cloned->getCategory();